<template>
    <form-page @submit="submit" v-loading="edit.loading">
        <el-form :model="edit.info"
                 :rules="rules"
                 ref="formRef">

            <el-form-item prop="password" label="新密码">
                <mi-input v-model="edit.info.password" type="password"/>
            </el-form-item>

            <el-form-item prop="password_confirm" label="确认密码">
                <mi-input v-model="edit.info.password_confirm" type="password" />
            </el-form-item>

        </el-form>
    </form-page>
</template>

<script setup lang="ts">
import {ref, onBeforeMount, inject} from "vue"
import {makeModelAuth} from "@/utils/auth"
import Edit from "@/model/edit";
import {FormInstance} from "element-plus";
import {useAdminStore} from "@/store/admin";
const edit = inject("password", new Edit({}))
const auth = makeModelAuth("admin")
const rules = {
    password:[{required:true, message:'必填'}],
    password_confirm:[{required:true, message:'必填'}],
}

const formRef = ref<FormInstance>()


const submit = () => {
    edit.submit({
        formRef:formRef.value,
        url: '/admin/setPassword',
        list: undefined,
    })
}

onBeforeMount(() => {
    edit.init(async () => {
        const admin = useAdminStore()
        edit.info = {
            id: admin.info.id,
            password: '',
            password_confirm: '',
        }
    })
})

</script>

<style scoped>

</style>
